package server.business.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import server.business.pojo.BloodProcessing;
import server.business.service.BloodProcessingService;
import server.business.utils.results.ysl.Result;

@Slf4j
@RequestMapping("/bloodprocessing")
@RestController
public class BloodProcessingController {


    @Autowired
    public BloodProcessingService bloodProcessingService;


    /**
     * 分页查询
     * @param currentPage
     * @param pageSize
     * @param
     * @return
     */
    @GetMapping("/normal/{currentPage}/{pageSize}")
    public Result getPage(@PathVariable int currentPage, @PathVariable int pageSize,
                          BloodProcessing bloodProcessing){
        IPage<BloodProcessing> page = bloodProcessingService.getPage(currentPage,pageSize,bloodProcessing);
        if (currentPage > page.getPages()) {
            page = bloodProcessingService.getPage((int) page.getPages(), pageSize, bloodProcessing);
        }
        return Result.success(page);
    }

    @GetMapping("/normal/validate")
    public Result validate(String id){

        if(bloodProcessingService.isExist(id)){
            return Result.success(bloodProcessingService.getBloodInformation(id));
        }else{
            return Result.error("500","不存在");
        }

    }

    @GetMapping("/normal/processing")
    public Result processing(BloodProcessing bloodProcessing){
        bloodProcessingService.processing(bloodProcessing);
        return Result.success();
    }

    @GetMapping("/normal/insert")
    public Result insert(BloodProcessing bloodProcessing){
        bloodProcessingService.insert(bloodProcessing);
        return Result.success("添加成功");
    }

    @GetMapping("/normal/delete")
    public Result delete(String processingId){
        bloodProcessingService.delete(processingId);
        return Result.success("成功");
    }
}
